package com.ler.yrmall.ware.controller;

import com.ler.yrmall.basic.Form;
import com.ler.yrmall.basic.Result;
import com.ler.yrmall.ware.entity.PurchaseEntity;
import com.ler.yrmall.ware.service.PurchaseService;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Arrays;


/**
 * 采购信息
 * @author Leron
 */
@RestController
@RequestMapping("/purchase")
public class PurchaseController {

    @Resource
    private PurchaseService purchaseService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public Result<?> list(Form request) {
        return Result.ok(purchaseService.find(request));
    }

    /**
     * 信息
     */
    @RequestMapping("/getById/{id}")
    public Result<?> getById(@PathVariable("id") Long id) {
        PurchaseEntity purchase = purchaseService.getById(id);
        return Result.ok(purchase);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public Result<?> save(@RequestBody PurchaseEntity purchase) {
        purchaseService.save(purchase);
        return Result.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public Result<?> update(@RequestBody PurchaseEntity purchase) {
        purchaseService.updateById(purchase);
        return Result.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public Result<?> delete(@RequestBody Long[] ids) {
        purchaseService.removeByIds(Arrays.asList(ids));
        return Result.ok();
    }

}
